import { reactive } from 'vue'
export function usePagination(pageSizes: Array<number>): any {
  const pagination = reactive({
    pageNum: 1,
    total: 0,
    pageSize: pageSizes[0],
    pageSizes,
    setCurrentPage: (newPage: number) => {
      pagination.pageNum = newPage
    },
    setPageSize: (newSize: number) => {
      pagination.pageSize = newSize
    },
    setTotal: (total: number) => {
      pagination.total = total
    },
    reset() {
      pagination.pageNum = 1
      pagination.total = 0
      pagination.pageSize = pagination.pageSizes[0]
    }
  })

  return {
    pagination,
    setCurrentPage: pagination.setCurrentPage,
    setPageSize: pagination.setPageSize,
    setTotal: pagination.setTotal
  }
}
